package com.itboye.mengwu.app.adapter;

import java.util.ArrayList;

import com.itboye.config.GlobalConfig;
import com.itboye.core.utils.XImageLoader;
import com.itboye.mengwu.R;
import com.itboye.mengwu.data.model.GoodsListModel;
import com.itboye.mengwu.data.model.GoodsListModel.GoodsList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class BaoShuiQuAdapter extends BaseAdapter {
	ArrayList<GoodsList> list;
	Context context;

	public BaoShuiQuAdapter(ArrayList<GoodsList> list2, Context context) {
		this.list = list2;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHour hour;
		if (convertView == null) {
			hour = new ViewHour();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_baoshuiqu, null);
			hour.txtbaoshuiCountext = (TextView) convertView
					.findViewById(R.id.txtbaoshuiCountext);
			hour.txtPopace = (TextView) convertView
					.findViewById(R.id.txtPopace);
			
			hour.txtPace = (TextView) convertView.findViewById(R.id.txtPace);
			hour.img_baoshui = (ImageView) convertView
					.findViewById(R.id.img_baoshui);
			
			hour.txtfreight=(TextView) convertView.findViewById(R.id.txtfreight);
			hour.txtcountry=(TextView) convertView.findViewById(R.id.txtcountry);
			convertView.setTag(hour);
		} else {
			hour = (ViewHour) convertView.getTag();
		}
		if (list.get(position).getImg() != null)
			XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
					+ list.get(position).getImg(), hour.img_baoshui);
		hour.txtPopace.setText(list.get(position).getTotal_sales() + "人购买了");
		hour.txtPace.setText("￥" + list.get(position).getPrice() + "元");
		hour.txtbaoshuiCountext.setText("\t\t\t\t"+list.get(position).getName());
//		if(list.get(position).getBorn().equals("")){
//			hour.txtcountry.setText("国家\t"+"中华人民共和国");
//		}else
//			
//		hour.txtcountry.setText("国家\t"+list.get(position).getBorn());
//		if(list.get(position).getTotal_sales().equals("0")){
//			hour.txtfreight.setText("包邮");
//		}else{
//			hour.txtfreight.setText("运费"+list.get(position).getMsg());
//		}
//		
		return convertView;
	}

	class ViewHour {
		private ImageView img_baoshui;
		private TextView txtPopace;
		private TextView txtbaoshuiCountext;
		private TextView txtPace;
		private TextView txtfreight;
		private TextView txtcountry;
	}

}
